/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uoc.libwatermarking.LSB;

import java.io.UnsupportedEncodingException;

/**
 *
 * @author rbuj
 */
final public class LSBShort extends LSB<Short> {

    public LSBShort() {
    }

    /**
     *
     * @param _sWatermark
     * @throws UnsupportedEncodingException
     * @since 2013-08-17
     */
    public LSBShort(String _sWatermark) throws UnsupportedEncodingException {
        super(_sWatermark);
    }

    /**
     *
     * @param b
     * @param posi
     * @return
     * @since 2013-08-17
     */
    @Override
    public Short embed(Short b, int posi) {
        short result = 0;
        int i = posi % aWatermark.length;
        result = (byte) ((b & 0xFFFE) | aWatermark[i]);
        return result;
    }

    /**
     *
     * @param sample
     * @param value
     * @return
     * @since 2013-08-21
     */
    @Override
    public Short embed(Short sample, boolean value) {
        if (value) {
            return (short) (sample | 0x0001);
        } else {
            return (short) (sample & 0xFFFE);
        }
    }

    /**
     *
     * @param sample
     * @return
     * @since 2013-08-17
     */
    @Override
    public Short extract(Short sample) {
        short result;
        result = (short) (sample & 0x0001);
        sample = (short) (sample & 0xFFFE);
        return result;
    }

    /**
     *
     * @return
     * @since 2013-08-17
     */
    @Override
    public String toString() {
        String result = "";
        for (int i = 0; i < aWatermark.length; i++) {
            result += aWatermark[i];
        }
        return result;
    }

    /**
     *
     * @return
     * @since 2013-08-17
     */
    @Override
    public int size() {
        return aWatermark.length;
    }

    @Override
    public boolean check(String message) {
        return (this.toString() == null ? message == null : this.toString().equals(message));
    }
}
